import type { RouteRecordRaw } from "vue-router"
import { createRouter, createWebHistory } from "vue-router"
import Layout from "@/layout/index.vue"

export const publicRoute: RouteRecordRaw[] = [
  {
    path: "/",
    component: Layout,
    redirect: "/dashboard",
    children: [
      {
        path: "dashboard",
        name: "Dashboard",
        component: () => import("@/views/dashboard/index.vue"),
        meta: {
          title: "dashboard",
          icon: "ant-design:dashboard-outlined",
          affix: true, // 默认固定标签
          noCache: false
        }
      }
    ]
  },
  {
    path: "/redirect",
    component: Layout,
    meta: {
      hidden: true
    },
    children: [
      {
        path: "/redirect/:path(.*)",
        component: () => import("@/views/redirect/index.vue")
      }
    ]
  },
  {
    path: "/login",
    name: "login",
    meta: {
      hidden: true
    },
    component: () => import("@/views/login/index.vue")
  },
  {
    path: "/profile",
    name: "profile",
    component: Layout,
    redirect: "/profile/index",
    meta: {
      hidden: true
    },
    children: [
      {
        path: "index",
        component: () => import("@/views/profile/index.vue")
      }
    ]
  }
]

export const asyncRoutes: RouteRecordRaw[] = [
  {
    path: "/documentation",
    component: Layout,
    redirect: "/documentation/index",
    children: [
      {
        path: "index",
        name: "documentation",
        component: () => import("@/views/documentation/index.vue"),
        meta: {
          title: "documentation",
          icon: "ant-design:file-text-outlined"
        }
      }
    ]
  },
  {
    path: "/guide",
    component: Layout,
    redirect: "/guide/index",
    children: [
      {
        path: "index",
        name: "guide",
        component: () => import("@/views/guide/index.vue"),
        meta: {
          title: "guide",
          icon: "ant-design:alert-outlined"
        }
      }
    ]
  },
  {
    path: "/system",
    component: Layout,
    redirect: "/system/menu",
    meta: {
      title: "system",
      icon: "ant-design:unlock-outlined"
      // alwaysShow: true
      // breadcrumb: false
    },
    children: [
      {
        path: "menu",
        name: "menu",
        component: () => import("@/views/system/menu/index.vue"),
        meta: {
          title: "menu",
          icon: "ant-design:menu-outlined"
        }
      },
      {
        path: "role",
        name: "role",
        component: () => import("@/views/system/role/index.vue"),
        meta: {
          title: "role",
          icon: "ant-design:usergroup-delete-outlined"
        }
      },
      {
        path: "user",
        name: "user",
        component: () => import("@/views/system/user/index.vue"),
        meta: {
          title: "user",
          icon: "ant-design:user-outlined"
        }
      }
    ]
  },
  {
    path: "/external-link",
    component: Layout,
    children: [
      {
        path: "http://www.baidu.com",
        redirect: "/",
        meta: {
          title: "externalLink",
          icon: "ant-design:link-outlined"
        }
      }
    ]
  }
]

export const routes = [...publicRoute, ...asyncRoutes]

export default createRouter({
  history: createWebHistory(),
  routes
})
